<?php
/**
 * Created by PhpStorm.
 * User: dingjinlai
 * Date: 2018/4/24
 * Time: 下午4:04
 */

defined('BASEPATH') OR exit('No direct script access allowed');

class Statistics extends Admin_Controller
{
    public function index()
    {
        

    }
    
    
    public function color_complex()
    {
        $this->load->model('Prepare_goods_model');
        $this->load->library('pagination');
    
        $assoc = $this->uri->uri_to_assoc();
    
        $_param_option = array(
            'add_time' => array(
                'col' => 'col-lg-4',
                'type' => 'dpd_time',
                'placeholder' => '上传时间'
            ),
            'coupon_code' => array(
                'col' => 'col-lg-3',
                'type' => 'text',
                'placeholder' => '优惠卷代码'
            ),
        );

        $_param = array(
            'add_time_start' => trim($this->input->get('add_time_start')),
            'add_time_end' => trim($this->input->get('add_time_end')),
            'coupon_code' => trim($this->input->get('coupon_code')),
            'page' => $assoc['page'] > 0 ? intval($assoc['page']) - 1 : 0
        );
        $res = $this->Prepare_goods_model->color_complex($_param);



        //分页
        $config['base_url'] = base_url('Statistics/') . 'color_complex/page/';
        $config['total_rows'] = $this->Prepare_goods_model->prepare_complex($_param);
        $config['num_links'] = 6;
        $config['per_page'] = $this->Prepare_goods_model->limit_rows;
        $config['use_page_numbers'] = true;
        $this->pagination->initialize($config);
        $prepare = $this->Prepare_goods_model->color_complex($_param);

        $data = array(
            'res' => $res,
            'pages' => $this->pagination->create_links(),
            'param_option' => $_param_option,
            'param' => $_param,
            'prepare' => $prepare,
        );
        
        $this->load->view('color_complex', $data);
    }
    //订单数量统计
    public function number_count(){
        $_param_option = array(
            'add_time' => array(
                'col' => 'col-lg-4',
                'type' => 'dpd_time',
                'placeholder' => '上传时间'
            ),
        );

        $_param = array(
            'add_time_start' => trim($this->input->get('add_time_start')),
            'add_time_end' => trim($this->input->get('add_time_end')),
        );

        if(!empty($_param['add_time_start'])){
            $add_time_start = strtotime($_param['add_time_start']);
            $add_time_end   = strtotime($_param['add_time_end']);
            $sql = "SELECT *,count(*) count_num FROM (SELECT count(*) num FROM pcs_order_goods og LEFT JOIN pcs_order_info oi on og.order_id = oi.order_id WHERE add_time between ".$add_time_start." AND ".$add_time_end." GROUP BY (oi.order_id) ) as res GROUP BY (num)";
        }else{
            $sql = "SELECT *,count(*) count_num FROM (SELECT count(*) num FROM pcs_order_goods og LEFT JOIN pcs_order_info oi on og.order_id = oi.order_id GROUP BY (oi.order_id)) as res GROUP BY (num)";
        }
        
        $res = $this->db->query($sql);
        $res = $res->result_array();
        $data = array(
            'param_option' => $_param_option,
            'prepare' => $res,
            'param' => $_param,
        );
        $this->load->view('number_count', $data);
    }

}
